package com.biboheart.adapter.support.enums;

import com.biboheart.adapter.support.BaseEnum;
import com.biboheart.adapter.support.EnumValueObject;

import java.util.ArrayList;
import java.util.List;

public enum InstructEnum implements BaseEnum<String, String> {
    INSTRUCT_CONVERT("convert", "转换"),
    INSTRUCT_CONCAT("concat", "连接"),
    INSTRUCT_REPLACE("replace", "替换"),
    INSTRUCT_SUBSTRING("substring", "截取"),
    INSTRUCT_SPLIT("split", "拆分"),
    INSTRUCT_CASE("case", "分支"),
    INSTRUCT_WHEN("when", "条件"),
    INSTRUCT_THEN("then", "选择"),
    INSTRUCT_ELSE("else", "否则"),
    INSTRUCT_END("end", "结束"),
    INSTRUCT_TIME("time", "时间"),
    INSTRUCT_TIMESTAMP("timestamp", "时间戳"),
    INSTRUCT_DATETIME("datetime", "日期时间"),
    INSTRUCT_ROUND("round", "保留小数位"),
    INSTRUCT_BINARY("binary", "二进制处理"),
    INSTRUCT_MAX("max", "取大值"),
    INSTRUCT_MIN("min", "取小值"),
    INSTRUCT_DEF("def", "默认值"),
    ;
    private final String code;
    private final String desc;

    InstructEnum(String code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    @Override
    public String code() {
        return code;
    }

    @Override
    public String desc() {
        return desc;
    }

    public static InstructEnum getInstruct(String code) {
        InstructEnum[] instructEnums = values();
        for (InstructEnum instructEnum : instructEnums) {
            if (instructEnum.code().equals(code)) {
                return instructEnum;
            }
        }
        return null;
    }

    public static boolean contains(String code) {
        InstructEnum[] instructEnums = values();
        for (InstructEnum instructEnum : instructEnums) {
            if (instructEnum.code().equals(code)) {
                return true;
            }
        }
        return false;
    }

    public static List<EnumValueObject<String, String>> list() {
        List<EnumValueObject<String, String>> list = new ArrayList<>();
        for (InstructEnum instructEnum : values()) {
            list.add(new EnumValueObject<>(instructEnum.code(), instructEnum.desc()));
        }
        return list;
    }
}
